<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<script>
    window.onload = function () {
        function ParentObj(name) {
            this.name = name;
            this.colors = ['red', 'black'];
            this.age=25
        }

        function ChildrenObj(name, age) {
            ParentObj.call(this, name); //继承了父类的属性和方法  其实就是重写了与父类相同的属性和方法 以覆盖父类的属性方法
            this.age = age;
        }

        ParentObj.prototype.sayName = function () {
            console.log(this.name);
        }

        ChildrenObj.prototype = new ParentObj();
        ChildrenObj.prototype.constructor = ChildrenObj;

        var c1 = new ChildrenObj("children", "22");
        console.log(c1);
        c1.sayName();

        ChildrenObj.prototype.sayAge = function () {
            console.log(this.age);
        }
        c1.sayAge();
    }
</script>

<body></body>

</html>